////////////////////////////////////////////////////////////////////////////////
///////// Product Market Competition and Convertible Debt Financing ////////////
///////// Cheng Lei, Evgeny Lyandres, Chris Veld, Ying Xia /////////////////////
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
* Date: April 27, 2024
* This do file contains code generating results for Tables 2 to 4
* Please define the path for datasets and the path for storing results before running the following program. 
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
*Control variable
global control size lage cash i.divd i.rep cf tangib capex mb rda Vol_12 

*Control variable for the predicted value estimated from regressions
global control1 size lage cash divd rep cf tangib capex mb rda Vol_12 

*Control variable: annual change in variables
global ccontrol csize ccash cdivy crep ccf ctangib ccapex cmb crda cvol_12

********************************************************************************
* Table 2 Product Market Competition and Fraction of Convertible Users
********************************************************************************

* Use the firm-year sample
* [Baseline_Firm_Year_Sample]

use "Path\Baseline_Firm_Year_Sample.dta", clear

* Panel A - Table 2
* Model 1
probit convo fld i.icode50 i.fyear,  vce(cluster gvkey)
estimates store a1
* Average marginal effect reported in table
margins, dydx(*) post
estimates store a2

* Model 2
probit convo fld $control i.icode50 i.fyear,  vce(cluster gvkey)
estimates store a3
* Average marginal effect reported in table
margins, dydx(*) post
estimates store a4

* Model 3
reghdfe convo fld $control , absorb(gvkey  fyear) vce(cluster gvkey) keepsingleton
estimates store a5


esttab  a1 a3 a2 a4 a5 using "Path\Table_2_Panel_A.csv", b(3) t(2) scalars("ll Log lik.") pr2(4) ar2(4) starlevels(* 0.10 ** 0.05 *** 0.01)  replace nogaps


* Panel B - Table 2
* Predicted value of convertible user estimated using Model 2

probit convo fld $control i.icode50 i.fyear,  vce(cluster gvkey)


margins, at((p1) fld (mean) $control1 icode50 fyear) at((p10) fld (mean) $control1 icode50 fyear) at((p25) fld (mean) $control1 icode50 fyear) at((p50) fld (mean) $control1 icode50 fyear) at((p75) fld (mean) $control1 icode50 fyear) at((p90) fld (mean) $control1 icode50 fyear) at((p99) fld (mean) $control1 icode50 fyear)
********************************************************************************

********************************************************************************
* Table 3 Product Market Competition and Adjustment of Convertible Debt Financing
********************************************************************************
* Panel A - Table 3

* Model 1
probit covdum fld $control i.icode50 i.fyear, vce(cluster gvkey)
estimates store a6
* Average marginal effect reported in table
margins, dydx(*) post
estimates store a7

* Model 2
probit covdum cfld $ccontrol  i.fyear,  vce(cluster gvkey)
estimates store a8
* Average marginal effect reported in table
margins, dydx(*) post
estimates store a9

* Model 3
probit covdum lcfld $ccontrol  i.fyear,  vce(cluster gvkey)
estimates store a10
* Average marginal effect reported in table
margins, dydx(*) post
estimates store a11

* Model 4
probit covdum llcfld $ccontrol  i.fyear,  vce(cluster gvkey)
estimates store a12
* Average marginal effect reported in table
margins, dydx(*) post
estimates store a13

* Model 5
reghdfe covdum fld $control, absorb(gvkey fyear) vce(cluster gvkey) keepsingleton
estimates store a14

* Model 6
reghdfe covdum cfld $ccontrol, absorb(  fyear) vce(cluster gvkey) keepsingleton
estimates store a15


esttab  a6 a8 a10 a12 a7 a9 a11 a13 a14 a15 using "Path\Table_3_Panel_A_Model_1to6.csv", b(3) t(2) scalars("ll Log lik.") pr2(4) ar2(4) starlevels(* 0.10 ** 0.05 *** 0.01)  replace nogaps



* Panel B - Table 3
* Predicted value of convertible user estimated using Model 1

probit covdum fld $control i.icode50 i.fyear,  vce(cluster gvkey)

margins, at((p1) fld (mean) $control1 icode50 fyear) at((p10) fld (mean) $control1 icode50 fyear) at((p25) fld (mean) $control1 icode50 fyear) at((p50) fld (mean) $control1 icode50 fyear) at((p75) fld (mean) $control1 icode50 fyear) at((p90) fld (mean) $control1 icode50 fyear) at((p99) fld (mean) $control1 icode50 fyear)

* Panel A - Table 3
* Use the issue-level sample including convertible and straight corporate bond issues
* [Convertible_Straight_Issue_Sample]

use "Path\Convertible_Straight_Issue_Sample.dta", clear

* Model 7
probit csdum fld $control i.icode50 i.fyear,  vce(cluster gvkey)
estimates store a1
* Average marginal effect reported in table
margins, dydx(*) post
estimates store a2

* Model 8
reghdfe csdum  fld $control , absorb(gvkey  fyear) vce(cluster gvkey) keepsingleton
estimates store a3


esttab  a1 a2 a3 using "Path\Table_3_Panel_A_Model_7and8.csv", b(3) t(2) scalars("ll Log lik.") pr2(4) ar2(4) starlevels(* 0.10 ** 0.05 *** 0.01)  replace nogaps

********************************************************************************


********************************************************************************
* Table 4 Product Market Competition and Proportion of Convertible Debt in Capital Structure
********************************************************************************
* Panel A - Table 4

* Use the firm-year sample
* [Baseline_Firm_Year_Sample]

use "Path\Baseline_Firm_Year_Sample.dta", clear

* Model 1
tobit fconv1 fld $control i.icode50 i.fyear, ll(0) vce(cluster gvkey)
estimates store a1
* Average marginal effect on the censored sample reported in table
margins, dydx(*) predict (ystar(0,.)) post
estimates store a2

* Model 2
reghdfe fconv1  fld $control , absorb(gvkey  fyear) vce(cluster gvkey) keepsingleton
estimates store a3

* Model 3
tobit fconv2 fld $control i.icode50 i.fyear, ll(0) vce(cluster gvkey)
estimates store a4
* Average marginal effect on the censored sample reported in table
margins, dydx(*) predict (ystar(0,.)) post
estimates store a5

* Model 4
reghdfe fconv2  fld $control , absorb(gvkey  fyear) vce(cluster gvkey) keepsingleton
estimates store a6


esttab  a1 a4 a2 a3 a5 a6 using "Path\Table_4_Panel_A.csv", b(3) t(2) scalars("ll Log lik.") pr2(4) ar2(4) starlevels(* 0.10 ** 0.05 *** 0.01)  replace nogaps


*Panel B - Table 4

* Predicted value of convertible/assets estimated using Model 1
tobit fconv1 fld $control i.icode50 i.fyear, ll(0) vce(cluster gvkey)

* Estimation based on censored sample
margins, at((p1) fld (mean) $control1 icode50 fyear) at((p10) fld (mean) $control1 icode50 fyear) at((p25) fld (mean) $control1 icode50 fyear) at((p50) fld (mean) $control1 icode50 fyear) at((p75) fld (mean) $control1 icode50 fyear) at((p90) fld (mean) $control1 icode50 fyear) at((p99) fld (mean) $control1 icode50 fyear) predict (ystar(0,.))

* Estimation based on truncated sample
margins, at((p1) fld (mean) $control1 icode50 fyear) at((p10) fld (mean) $control1 icode50 fyear) at((p25) fld (mean) $control1 icode50 fyear) at((p50) fld (mean) $control1 icode50 fyear) at((p75) fld (mean) $control1 icode50 fyear) at((p90) fld (mean) $control1 icode50 fyear) at((p99) fld (mean) $control1 icode50 fyear) predict (e(0,.))


* Predicted value of convertible/assets estimated using Model 3
tobit fconv2 fld $control i.icode50 i.fyear, ll(0) vce(cluster gvkey)

* Estimation based on censored sample
margins, at((p1) fld (mean) $control1 icode50 fyear) at((p10) fld (mean) $control1 icode50 fyear) at((p25) fld (mean) $control1 icode50 fyear) at((p50) fld (mean) $control1 icode50 fyear) at((p75) fld (mean) $control1 icode50 fyear) at((p90) fld (mean) $control1 icode50 fyear) at((p99) fld (mean) $control1 icode50 fyear) predict (ystar(0,.))

* Estimation based on truncated sample
margins, at((p1) fld (mean) $control1 icode50 fyear) at((p10) fld (mean) $control1 icode50 fyear) at((p25) fld (mean) $control1 icode50 fyear) at((p50) fld (mean) $control1 icode50 fyear) at((p75) fld (mean) $control1 icode50 fyear) at((p90) fld (mean) $control1 icode50 fyear) at((p99) fld (mean) $control1 icode50 fyear) predict (e(0,.))

********************************************************************************

////////////////////////////////////////////////////////////////////////////////
* The above codes generate the result, and the format of table is finalised in Excel. 
* For Probit and Tobit regressions, vce(cluster gvkey) is equivalent to Cluster(gvkey)
* For Probit and Tobit regressions, the average marginal effect is reported in the table
* Control and Control1 have the same list of independent variables, but Control has dummy indicator for divd and rep. For estimating the predicted value in Probit and Tobit regressions, we cannot add factor indicator to independent variables. 
* Keepsingleton allows the estimation to be conducted based on the full sample. The results are unchanged if running without this requirement. 
////////////////////////////////////////////////////////////////////////////////

